package com.hs.myshell.action;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;

import com.hs.myshell.EditorDialog;
import com.hs.myshell.edit.TerminalEditor;
import com.hs.myshell.edit.TerminalEditorInput;
import com.hs.myshell.nls.Messages;
import com.hs.myshell.ssh.ISSHClient;
import com.hs.myshell.ssh.ISSHClientSSHJ;

/**
 * 
 */
public class EditTerminalSettingAction extends Action implements ISelectionListener, IWorkbenchAction {

	private final IWorkbenchWindow window;
	private IStructuredSelection selection;
	
	
	
	public EditTerminalSettingAction(IWorkbenchWindow window,IStructuredSelection selection) {
		this.window = window;
		this.selection = selection;
		window.getSelectionService().addSelectionListener(this);
	}

	@Override
	public void dispose() {
		window.getSelectionService().removeSelectionListener(this);
	}

	@Override
	public void selectionChanged(IWorkbenchPart part, ISelection input) {
		if (input instanceof IStructuredSelection) {
			selection = (IStructuredSelection)input;
			setEnabled(selection.size() == 1 && selection.getFirstElement() instanceof Object);
		}else {
			setEnabled(false);
		}

	}

	public void run() {
		Object item = selection.getFirstElement();
		Object dd = (Object)item;
		IWorkbenchPage page = window.getActivePage();
		try {
			new EditorDialog(Display.getDefault().getActiveShell(),null).create();
		}catch(Exception e) {
			e.printStackTrace();
		}
	}
}
